#include <cstdarg>
#include <cstdlib>
#include <sstream>

using namespace std;

int str2num(string s) {
    stringstream ss;
    int n;
    ss << s;
    ss >> n;
    return n;
}

double VaSum(const char *fmt, ...) {
    va_list ap; /* points to each unnamed arg in turn */
    char *p, *sval;
    int ival;
    double dval;

    double res = 0;

    va_start(ap, fmt); /* make ap point to 1st unnamed arg */

    for (auto p = fmt; *p; p++) {
        if (*p != '%') {
            continue;
        }
        switch (*++p) {
        case 'd':
            ival = va_arg(ap, int);
            res += ival;
            break;
        case 'f':
            dval = va_arg(ap, double);
            res += dval;
            break;
        case 's':
            sval = va_arg(ap, char *);
            res += str2num(string(sval));
            break;
        default:
            break;
        }
    }
    va_end(ap); /* clean up when done */

    return res;
}
